@echo off
chcp 65001 >nul
title AI VTuber Test

REM Set color
color 0A

echo.
echo ======================================================================
echo                AI VTuber - Full Test Launcher
echo ======================================================================
echo.
echo Configuration:
echo   TTS Engine: ChatTTS 0.2.4
echo   Voice: Girl Voice (Seed 5201)
echo   Live2D Model: Hiyori
echo   HTTP Server: localhost:8000
echo   WebSocket: localhost:8765
echo.
echo ======================================================================
echo.

REM Change to script directory
cd /d "%~dp0"

REM Try to activate Anaconda environment if exists
if exist "D:\anaconda\Scripts\activate.bat" (
    echo Activating Anaconda environment...
    call D:\anaconda\Scripts\activate.bat D:\anaconda
    echo.
)

REM Check Python
python --version >nul 2>&1
if errorlevel 1 (
    echo Error: Python not found!
    echo.
    echo Please ensure:
    echo   1. Python 3.12 is installed
    echo   2. Python is added to system PATH
    echo.
    pause
    exit /b 1
)

REM Display Python version
echo Python Environment:
python --version
echo.

REM Check if yaml module is available
echo Checking dependencies...
python -c "import yaml" >nul 2>&1
if errorlevel 1 (
    echo.
    echo Warning: yaml module not found!
    echo Installing all required dependencies from requirements.txt...
    echo This may take a few minutes...
    echo.
    pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
    if errorlevel 1 (
        echo.
        echo Error: Failed to install dependencies!
        echo.
        echo Please check:
        echo   1. requirements.txt file exists
        echo   2. Internet connection is working
        echo   3. No permission issues
        echo.
        pause
        exit /b 1
    )
    echo.
    echo Dependencies installed successfully!
    echo.
)
echo Dependencies check passed
echo.

REM Check config file
if not exist "config\config.yaml" (
    echo Error: Config file not found - config\config.yaml
    echo.
    pause
    exit /b 1
)

echo Config file check passed
echo.

REM Check voice file
if not exist "speakers\girl_5201.pt" (
    echo Warning: Voice file not found - speakers\girl_5201.pt
    echo    Will use seed value to generate voice
    echo.
)

echo ======================================================================
echo                      Starting Test Program
echo ======================================================================
echo.
echo Tips:
 echo   - Live2D page will open automatically
 echo   - Select "2 - Interactive Mode" for testing
 echo   - Input any text to simulate chat
 echo   - Input exit or quit to stop
echo.
echo Starting...
echo.

REM Run test program
python test_local_enhanced.py

REM Check exit status
if errorlevel 1 (
    echo.
    echo ======================================================================
    echo Program exited with error!
    echo ======================================================================
    echo.
    echo Possible reasons:
    echo   1. Port occupied (8000 or 8765)
    echo   2. Dependencies not installed
    echo   3. Config file error
    echo.
    echo Suggestions:
    echo   - Check port occupation
    echo   - Run: pip install -r requirements.txt
    echo   - Check config file: config\config.yaml
    echo.
    pause
    exit /b 1
) else (
    echo.
    echo ======================================================================
    echo Test completed successfully
    echo ======================================================================
    echo.
)

pause
